package com.bjx.flow.mmx.task.handler;

import cn.hutool.core.collection.ListUtil;
import com.bjx.flow.mmx.bean.MmxNextNodeData;
import com.bjx.flow.mmx.bean.MmxNodeData;
import com.bjx.flow.mmx.constant.MmxNodeConstant;
import com.bjx.flow.mmx.extension.MmxAbstractApprover;
import com.bjx.flow.mmx.service.MmxFlowBranchService;
import com.bjx.flow.mmx.service.MmxFlowInstanceService;
import com.bjx.flow.mmx.service.MmxFlowTaskService;
import com.bjx.flow.mmx.task.MmxAbstractTaskHandler;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;
import java.util.Optional;

/**
 * @desc: 用户任务处理
 * @author: liushuai
 * @date: 2023/5/23 17:26
 */
@Service(MmxNodeConstant.START + MmxNodeConstant.TASK_FLAG)
public class MmxStartTaskHandler extends MmxAbstractTaskHandler {
    @Resource
    private MmxFlowTaskService flowTaskService;
    @Resource
    private MmxAbstractApprover approverService;

    @Resource
    private MmxFlowBranchService flowBranchService;

    @Resource
    private MmxFlowInstanceService flowInstanceService;

    @Override
    public List<MmxNodeData> simulationExecute(MmxNextNodeData nextNodeData) {
        MmxNodeData nodeData = nextNodeData.getNodeDataList().get(0);
        List<String> approver = approverService.getApprover(nodeData, Optional.ofNullable(nextNodeData.getVariables()).orElse(new HashMap<>()));
        nodeData.setAssignees(approver);
        return ListUtil.toList(nodeData);
    }

    @Override
    public void passExecute(MmxNextNodeData nextNodeData) {
    }

    @Override
    public void rejectExecute(MmxNextNodeData nextNodeData) {

    }

    @Override
    public void sendBackExecute(MmxNextNodeData nextNodeData) {

    }

    @Override
    public void appointExecute(MmxNextNodeData nextNodeData) {

    }
}
